/*
 * Copyright (c) Created by T C L on 2019.7.9.
 */

package cn.mumzone.pos.ui.adapter;

import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import cn.mumzone.basic.adapter.rv.CommonAdapter;
import cn.mumzone.basic.adapter.rv.ViewHolder;
import cn.mumzone.basic.util.ListUtil;
import cn.mumzone.basic.util.StringUtils;
import cn.mumzone.pos.R;
import cn.mumzone.pos.model.SalesTimesCard;
import cn.mumzone.pos.ui.dialog.TimesCardPurchaseDialogFragment;
import cn.mumzone.pos.util.GoodsUtil;

public class ADA_SalesTimesCard extends CommonAdapter<SalesTimesCard> {

    private String memberPhone;

    public ADA_SalesTimesCard(Context context, String memberPhone) {
        super(context);
        this.memberPhone = memberPhone;
    }


    @Override
    protected int itemLayoutId() {
        return R.layout.item_sales_time_card;
    }

    @Override
    protected void convert(ViewHolder holder, final SalesTimesCard salesTimesCard, int position) {
        // 设置次卡信息
        holder.setText(R.id.tv_card_name, StringUtils.get(salesTimesCard.getName()));
        holder.setText(R.id.tv_card_des, StringUtils.get(salesTimesCard.getServicesName()));
        holder.setText(R.id.tv_card_use_info, String.format("%s次", StringUtils.get(salesTimesCard.getTimes())));
        holder.setText(R.id.tv_card_last_time, String.format("有效期：%s个月", salesTimesCard.getValidDay()));

        holder.setText(R.id.tv_card_type, GoodsUtil.isLimitTimeCard(salesTimesCard) ? "限时卡" : "普通卡");
        holder.setVisible(R.id.iv_limit_card, GoodsUtil.isLimitTimeCard(salesTimesCard));

        holder.setText(R.id.tv_goods_price, "¥" + salesTimesCard.getOriginPrice());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TimesCardPurchaseDialogFragment timesCardPurchaseDialogFragment = new TimesCardPurchaseDialogFragment();
                Bundle bundle = new Bundle();
                bundle.putString("memberPhone", memberPhone);
                bundle.putSerializable("salesTimesCard", salesTimesCard);
                timesCardPurchaseDialogFragment.setArguments(bundle);
                timesCardPurchaseDialogFragment.show(((AppCompatActivity) mContext).getSupportFragmentManager(),
                        "timeCardPurchase");
            }
        });
    }



}
